/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.main;

import org.koron.ebs.mybatis.ADOSessionImpl;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Bean(name = "primaryDataSource")
    @Qualifier("primaryDataSource")
    @ConfigurationProperties(prefix="spring.datasource.safety.base")
    public DataSource primaryDataSource() {
        DataSource ds =  DataSourceBuilder.create().build();
        ADOSessionImpl session = new ADOSessionImpl();
//        session.addInterceptor("_default","com.github.pagehelper.PageInterceptor");
        session.addInterceptor("_default", "com.koron.util.PageInterceptor");
        //开启/关闭-自动转换驼峰标识
        SessionFactory.setMapUnderscoreToCamelCase(true);
        session.registeDataSourceMap("_default", ds);
        return ds;
    }
    @Bean(name = "safetyTemplateSource")
    @Qualifier("primaryDataSource")
    @ConfigurationProperties(prefix="spring.datasource.safety.template")
    public DataSource commonDataSource() {
        DataSource ds =  DataSourceBuilder.create().build();
        ADOSessionImpl session = new ADOSessionImpl();
        session.registeDataSourceMap("_template", ds);
        return ds;
    }

    @Bean(name = "safetyBaseSource")
    @Qualifier("primaryDataSource")
    @ConfigurationProperties(prefix="spring.datasource.safety.business")
    public DataSource safetyBusinessSource() {
        DataSource ds =  DataSourceBuilder.create().build();
        ADOSessionImpl session = new ADOSessionImpl();
        //开启/关闭-自动转换驼峰标识
        SessionFactory.setMapUnderscoreToCamelCase(true);
        session.registeDataSourceMap("_base", ds);
        return ds;
    }
}